
#include "bigBlock.h"
#include "house.h"



bigBlock::bigBlock(house* l){
	home=l;
x=0;
y=0;
srand(time(0));
ang=rand()%360;
r=4;
d=false;
}
bigBlock::bigBlock(house* l,int poop, int pee){
	home=l;
x=poop;
y=pee;
ang=rand()%360;
r=4;
d=false;
}
bigBlock::bigBlock(house* l,int poop,int pee,int angl){
	home=l;
x=poop;
y=pee;
ang=angl;
r=4;
d=false;
}

void bigBlock::draw(){

/*

	SDL_Rect offset; 
	offset.x = static_cast<int>(x); 
	offset.y = static_cast<int>(y); 
	SDL_BlitSurface( home->blockpng, NULL, home->screen, &offset ); 
*/


	Draw_Circle(home->screen,static_cast<int>(x), static_cast<int>(y),r,0xAACCFFFF);
	//Draw_Rect(home->screen,static_cast<int>(x-r/2), static_cast<int>(y-r/2),r,r,0xAACCFFFF);

}


void bigBlock::move(){
	x+=cos(ang)*3; 
	y+=sin(ang)*3;	
	

	for (int i=0; i< home->blockcount;i++){
		if (home->blocks[i]!=this){
	double d=sqrt((home->blocks[i]->x-x)*(home->blocks[i]->x-x)+(home->blocks[i]->y-y)*(home->blocks[i]->y-y));
		if (d<r+home->blocks[i]->r&&home->blocks[i]->d==false&&this->d==false){
			r+=(home->blocks[i]->r);
			home->blocks[i]->d=true;
		}
	}
	}

	if (x-r<0){
		x=0+r;
		ang=180+ang;
	}
	if(x+r>526){
		x=526-r;
		ang=180+ang;
	}
	if(y-r<0){
		y=0+r;
		ang=180+ang;
	}
	if(y+r>526){
		y=526-r;
		ang=180+ang;
	}

}

void bigBlock::bup(){



home->makeBlock(x+cos(1.0)*r,y+sin(0.0)*r);
home->getBlock(home->blockcount)->r=r/5;
home->makeBlock(x+cos(0.0)*r,y+sin(0.0)*r);
home->getBlock(home->blockcount)->r=r/5;
home->makeBlock(x+cos(0.0)*r,y+sin(1.0)*r);
home->getBlock(home->blockcount)->r=r/5;
x+=cos(1.0)*r;
y+=sin(1.0)*r;
r/=5;

return;
}